<?php
class UserFactory{

  public static function GetUserByID($id)
  {
		$User = new User();
		$sql = mysql_query("SELECT * FROM " . USER_TABLE . "  WHERE id='".$id."'");
		if (!$sql) {
			return false;
		}
		$temp = mysql_fetch_assoc($sql);
		$User->setId($id);
		$User->setTeam($temp["team"]);
		$User->setOrdre($temp["ordre"]);
		$User->setPseudo($temp["pseudo"]);
		$User->setMail($temp["mail"]);
		$User->setNiveau($temp["niveau"]);
		$User->setDateInscription($temp["date"]);
		$User->setAvatar($temp["avatar"]);
		$User->setSignature($temp["signature"]);
		$User->setRace($temp["race"]);
		$User->setBnetId($temp["bnetid"]);
		$User->setLigue($temp["ligue"]);
		$User->setPass($temp["pass"]);
		return $User;
  }
  
  public static function GetUserByPseudo($pseudo)
  {
		$User = new User();
		$pseudo = htmlentities($pseudo, ENT_QUOTES);
		$sql = mysql_query("SELECT * FROM " . USER_TABLE . " WHERE pseudo='".$pseudo."'");
		if (!$sql) {
			return false;
		}
		$temp = mysql_fetch_assoc($sql);
		$User->setId($temp["id"]);
		$User->setTeam($temp["team"]);
		$User->setOrdre($temp["ordre"]);
		$User->setPseudo($temp["pseudo"]);
		$User->setMail($temp["mail"]);
		$User->setNiveau($temp["niveau"]);
		$User->setDateInscription($temp["date"]);
		$User->setAvatar($temp["avatar"]);
		$User->setSignature($temp["signature"]);
		$User->setRace($temp["race"]);
		$User->setBnetId($temp["bnetid"]);
		$User->setLigue($temp["ligue"]);
		$User->setPass($temp["pass"]);
		return $User;
  }
  
  public static function CreateUser($user)
  {
	$sql = mysql_query("INSERT INTO " . USER_TABLE . " SET niveau = '" . $user->getNiveau() . "',date = '" . $user->getDateInscription() . "',avatar = '" . $user->getAvatar() . "', team = '" . $user->getTeam() . "', pseudo = '" . $user->getPseudo() . "', mail = '" . $user->getMail() . "', ordre = '" . $user->getOrdre() . "', signature = '" . $user->getSignature() . "',race = '" . $user->getRace(). "', id = '" . $user->getId() . "', pass = '" . $user->getPass() . "', ligue = '" . $user->getLigue() . "', bnetid = '" . $user->getBnetId() . "'");
  }
  
  public static function UpdateUser($user)
  {
	$sql = mysql_query("UPDATE " . USER_TABLE . " SET niveau = '" . $user->getNiveau() . "',date = '" . $user->getDateInscription() . "',avatar = '" . $user->getAvatar() . "', team = '" . $user->getTeam() . "', pseudo = '" . $user->getPseudo() . "', mail = '" . $user->getMail() . "', ordre = '" . $user->getOrdre() . "', signature = '" . $user->getSignature() . "',race = '" . $user->getRace(). "', ligue = '" . $user->getLigue() . "', bnetid = '" . $user->getBnetId() . "' WHERE id = '" . $user->getId() . "'");
  }
  
  public static function UpdateUserPass($id,$pass)
  {
	$sql = mysql_query("UPDATE " . USER_TABLE . " SET pass = '" . $pass . "' WHERE id = '" . $id . "'");
  }
 
  public static function GetUniqueId()
  {
	do{
		$id = sha1(uniqid());
	} while (mysql_num_rows(mysql_query('SELECT * FROM ' . USER_TABLE . ' WHERE id=\'' . $id . '\' LIMIT 1')) != 0);
	return $id;
  }
 }
 
 class User{
	private $Id;
	private	$Team;
	private	$Ordre;
	private	$Pseudo;
	private	$Mail;
	private	$Niveau;
	private	$DateInscription;
	private	$Avatar;
	private	$Signature;
	private	$Race;
	private	$BnetId;
	private	$Ligue;
	private $Pass;

	public function getId()
	{
		return $this->Id;
	}
  
  	public function getTeam()
	{
		return $this->Team;
	}
	
	public function getOrdre()
	{
		return $this->Ordre;
	}
	
	public function getPseudo()
	{
		return $this->Pseudo;
	}
	
	public function getMail()
	{
		return $this->Mail;
	}
	
	public function getNiveau()
	{
		return $this->Niveau;
	}
	
	public function getDateInscription()
	{
		return $this->DateInscription;
	}
	
	public function getNkDate()
	{
		return nkDate($this->DateInscription);
	}
	
	public function getAvatar()
	{
		return html_entity_decode($this->Avatar);
	}
	
	public function getSignature()
	{
		return html_entity_decode($this->Signature);
	}
	
	public function getPass()
	{
		return $this->Pass;
	}
	
	public function getRace()
	{
		return $this->Race;
	}
	
	public function getBnetId()
	{
		return html_entity_decode($this->BnetId);
	}
	
	public function getLigue()
	{
		return $this->Ligue;
	}

	public function setId($id)
	{
		$this->Id=$id;
	}
  
  	public function setTeam($team)
	{
		$this->Team=$team;
	}
	
	public function setOrdre($ordre)
	{
		$this->Ordre=$ordre;
	}
	
	public function setPseudo($pseudo)
	{
		$this->Pseudo=htmlentities($pseudo, ENT_QUOTES);
	}
	
	public function setMail($mail)
	{
		$this->Mail=$mail;
	}
	
	public function setNiveau($niveau)
	{
		$this->Niveau=$niveau;
	}
	
	public function setDateInscription($dateInscription)
	{
		$this->DateInscription=$dateInscription;
	}
	
	public function setAvatar($avatar)
	{
		$this->Avatar=htmlentities(mysql_real_escape_string(stripslashes($avatar)));
	}
	
	public function setSignature($signature)
	{
		$this->Signature=htmlentities(mysql_real_escape_string(stripslashes($signature)));
	}
	
	public function setRace($race)
	{
		$this->Race=$race;
	}
	
	public function setBnetId($bnetId)
	{
		$this->BnetId=$bnetId;
	}
	
	public function setLigue($ligue)
	{
		$this->Ligue=$ligue;
	}

	public function setPass($pass)
	{
		$this->Pass=$pass;
	}
 }
 ?>